package com.example.mybatis.service.impl;

import cn.hutool.core.collection.CollUtil;

import com.example.mybatis.bean.StudentInformation;
import com.example.mybatis.mapper.StudentInformationMapper;
import com.example.mybatis.service.StudentInformationService;
import com.example.mybatis.utils.ResultUtil;
import com.example.mybatis.utils.validator.DataValidator;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class StudentInformationImpl implements StudentInformationService {
    @Resource
    StudentInformationMapper studentInformationMapper;



    public ResultUtil selectList(String name,String status) {
        List<StudentInformation> dataList = studentInformationMapper.selectList(name, status);
        return ResultUtil.ok().put("dataList", dataList);
    }

    public ResultUtil save(StudentInformation studentInformation) {
        DataValidator.validator(studentInformation);
        studentInformationMapper.insertBatch(CollUtil.newArrayList(studentInformation));
        return ResultUtil.ok();
    }

    @Override
    public ResultUtil update(StudentInformation studentInformation) {
        DataValidator.validator(studentInformation);
        studentInformationMapper.update(studentInformation);
        return ResultUtil.ok();
    }

    @Override
    public ResultUtil removeById(Long id) {
        studentInformationMapper.deleteById(id);
        return ResultUtil.ok();
    }

    @Override
    public ResultUtil getById(Long id) {
        StudentInformation studentInformation = null;
        // 修改根据id查询原值
        if (id != null) {
            studentInformation = studentInformationMapper.selectById(id);
        }
        return ResultUtil.ok().put("studentInformation",studentInformation);

    }
}
